<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>角色管理</title>
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/style/redmond/jquery-ui-1.8.11.css"
	type="text/css" media="all" />
<script type="text/javascript"
	src="<%=request.getContextPath()%>/script/lib/jquery-1.5.1.js"></script>
	<script type="text/javascript"
	src="<%=request.getContextPath()%>/script/lib/populate.js"></script>
		<script type="text/javascript"
	src="<%=request.getContextPath()%>/script/lib/populateclass.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/script/lib/jquery-ui-1.8.11.js"></script>

<script type="text/javascript"
	src="<%=request.getContextPath()%>/script/lib/jquery.guigrid.js"></script>
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/style/ui.grid/ui.guigrid.css" />
<script type="text/javascript">
	$(function(){
		$.ajax({
            type: 'POST',
            url: 'rolerule',
            dataType: 'json',
            success : function(data) {
			    var rules = eval('('+data+')');
		    	var obj = document.getElementById('rolerule');;
			    for(var i=0;i<rules.length;i++){
			    	var rule = rules[i];
			    	var opn = document.createElement("OPTION");
			        obj.appendChild(opn);
			        opn.innerHTML = rule.value;
			        opn.value = rule.code;
			        <%if(request.getAttribute("rolerule") ==null || request.getAttribute("rolerule").equals("-1")) {%>
			        <%}else {%>
			        if(rule.code=='<%=request.getAttribute("rolerule")%>'){
			        	opn.selected = true;
			        }
			        <%}%>
			        
			    }
			},
			error: function(data) { alert('获取角色类型异常'); }
        });
	});
	$(function() {
		$("#gridtest").guigrid({
			height : 200, //flexigrid插件的高度，单位为px
			url : 'managerroles?rolename=<%=request.getAttribute("rolename") ==null ?"":request.getAttribute("rolename") %>&rolerule=<%=(request.getAttribute("rolerule") ==null || request.getAttribute("rolerule").equals("-1")) ?"" :request.getAttribute("rolerule")%>', //ajax url,ajax方式对应的url地址page/grid/sample-data.json
			keyCol:"roleid",
			colModel : [ {
				display : '角色名称',
				width:($("#gridtest")[0].clientWidth-90)*(1/2)+18,
				name : 'rolename',
				sortable : true,
				align : 'left',
				hide : false
			}, {
				display : '角色类型',
				width:($("#gridtest")[0].clientWidth-90)*(1/2)+18,
				name : 'rolerule',
				sortable : false,
				align : 'left'
			} ],
			buttons : [ {
				name : 'Add',
				displayname : "增加角色",
				bclass : 'Add',
				rule:'0',
				onpress : toolbarItem_onclick
			}, {
				name : 'Modify',
				displayname : "修改角色",
				bclass : 'Modify',
				rule:'1',
				onpress : toolbarItem_onclick
			}, {
				name : 'Delete',
				displayname : "删除角色",
				bclass : 'Delete',
				rule:'2',
				onpress : toolbarItem_onclick
			} ],
			usepager : true,
			useRp : true,
			rowbinddata : true,
			showcheckbox : true,
			showTableToggleBtn : true,
			autowidth:true
		});
		function toolbarItem_onclick(cmd, grid) {
			var btn = document.getElementsByName(cmd);
			if(btn && btn[0]){
				if(btn[0].disabled=="disabled"){
					return false;
				}
			}else{
				return false;
			}
			if (cmd == "Add") {
				ShowIframe('添加角色','roles?method=addrole',600,350);
			} else if (cmd == "Delete") {
				 if(confirm('删除的数据无法恢复，您确定删除吗？','删除提示')){
					deleteIds();
				}  
				 /**
				 处理点击，添加按钮的rule
				 **/
				 /* $("#gridtest").bind("click",function(){
						var td = event.srcElement;
						if(($("#gridtest").guigrid("getCheckedRows")).length>1){
							alert("hehe");
						}
					}); */
					//alert($("tr.trSelected").length);
			} else{
				var checkedRows = $("#gridtest").guigrid("getCheckedRows");
				ShowIframe('修改角色','roles?method=updaterole&roleid='+checkedRows[0],600,350);
				//var o = $("#gridtest").guigrid("getCheckedRows");
				//alert(o);
				/* $("#gridtest").guigrid("option",{
						colModel : [ {
							display : '111代码类型',
							name : 'codetype'
						}, {
							display : '222代码描述',
							name : 'description'
						}, {
							display : '333状态',
							name : 'status'
						}]
				}); */
			}
		}
	});
	
	function deleteIds(){
		var checkedRows = $("#gridtest").guigrid("getCheckedRows");
		var param="";
		for(var i=0; i<checkedRows.length;i++){
			param = param+checkedRows[i]+","
		}
		param = param.substring(0, param.length-1);
		$.ajax({
	        type: 'POST',
	        url: 'deleteRole?roleIds='+param,
	        dataType: 'json',
	        success : function(data) {
	        	var deleteMsg = eval('('+data+')');
	        	alert(deleteMsg.msg);
	        	$("#gridtest").guigrid("reload");
			},
			error: function(data) { alert('删除角色异常'); }
	    });
	}
	function query(){
		/* $("#gridtest").guigrid("reload", {
			"extParam":[
			    { name: 'managername', value: $("#managername").val() },
			    { name: 'roleid', value: ($("#roleid").val()=='-1'?'':$("#roleid").val()) },
			]
		});
		return false; */
	}
	function resetCondition(){
		$("#rolename").val("");
		$("#rolerule").val("-1");
	}
</script>
</head>
<body>
	<div id="currentPossition" style="vertical-align: center">
	<table style="table-layout: fixed;" cellpadding="0" cellspacing="1" border="0">
	<tr><td><img width="7" height="7"  src="images/title/title-icon.gif" border="0" hspace="8" complete="complete"/></td>
	<td style="font-size: 9pt;">当前位置：系统管理>角色管理</td></tr></table> </div>
	<div align="left" style="border-color: #7f9db9;border-width: 1px;border-style: solid; margin-top: 6px;" >
		<div align="center" style="height:150px;width:100%;background-color:#f1f5ff;">
		<div align="left" style="height:25px;width:100%;background-color:#d5e2f2;font-size: 12px;vertical-align: ">
			<table style="vertical-align: middle;height: 100%;"><tr><td><img width="7" height="7"  src="images/title/title-icon.gif" border="0" hspace="8" complete="complete"/>查询条件</td></tr></table>
		</div>
			<form action="roles" onSubmit="return query()">
				<table style="width: 100%;">
					<tr >
						<td style="height:50px;font-size: 12px;width:15%;" align="right">角色名称：</td>
						<td style="width:35%;" align="left"><input type="text" name="rolename" id="rolename" value="<%=request.getAttribute("rolename") ==null ?"":request.getAttribute("rolename") %>" style="width: 90%" />
						</td>
						<td style="font-size: 12px;width:15%;" align="right">角色类型：</td>
						<td style="width:35%;" align="left">
						<select  name="rolerule" id="rolerule" style="width: 90%">
							<option value='-1'>请选择……</option>
						</select>
						</td>
					</tr>
					<tr>
						<td style="height:30px;font-size: 12px;width:15%;" align="right" colspan="4"></td>
					</tr>
					<tr >
						<td ></td>
						<td  align="right" style="height:22px;vertical-align: top;"><div style="float: right;margin-right: 15px;">
						<input type="submit" value="查询" style="width: 60px; border-style: solid;border-width: 1px;border-color: #7f9db9;font-size: 9pt;background-color:#f1f5ff ;padding-top: 2px;" /></div>
						</td>
						<td  align="left" style="vertical-align: top;">
						<div style="float: left;margin-left: 15px;"><input type="button" onclick="resetCondition();" value="重置" style="width: 60px; border-style: solid;border-width: 1px;border-color: #7f9db9;font-size: 9pt;background-color:#f1f5ff;padding-top: 2px; " /></div>
						</td>
						<td></td>
					</tr>
				</table>
			</form>
		</div>
		<div id="gridtest"></div>
	</div>
</body>
</html>